import { createRouter, createWebHistory, createWebHashHistory} from 'vue-router'
import screen from '@/views/screen/index.vue'

const router = createRouter({
  // history: createWebHistory(import.meta.env.VITE_PUBLIC_PATH),
  history: createWebHashHistory(import.meta.env.VITE_PUBLIC_PATH),
  routes: [
    {
      path: '/',
      name: 'screen',
      component: screen,
      meta:{title:"为老助餐可视化平台"},
    },
    {
      path: '/screen2',
      name: 'screen2',
      component: () => import('@/views/screen2/index.vue'),
      meta:{title:"医疗结合服务数字化驾驶舱"},
    },
    {
      path: '/home',
      name: 'home',
      component:() => import('@/views/home.vue'),
    },
    {
      path: '/component',
      name: 'component',
      component:() => import('@/views/component.vue'),
    },
    {
      path: '/demo',
      name: 'demo',
      component:() => import('@/views/demo/index.vue'),
      children:[
        {
          title:"介绍",
          name:"introduce",
          path:"introduce/introduce",
          component:() => import('@/views/demo/introduce/introduce.vue'),
        },
        {
          title:"选项式API / 组合式api",
          name:"api",
          path:"api/api",
          component:() => import('@/views/demo/api/api.vue'),
        },
        {
          title:"响应式",
          name:"reactivity",
          path:"reactivity/reactivity",
          component:() => import('@/views/demo/reactivity/reactivity.vue'),
        },
        {
          title:"v-for",
          name:"vFor",
          path:"vFor/vFor",
          component:() => import('@/views/demo/vFor/vFor.vue'),
        },
        {
          title:"event",
          name:"event",
          path:"event/event",
          component:() => import('@/views/demo/event/event.vue'),
        },
      ]
    },
    {
      path: '/:page*',
      name: '404',
      component:() => import('@/views/404.vue'),
      meta:{title:"404"},
    },
  ]
})

router.beforeEach((to, from, next) => {
  if(to.matched.length == 0){
    router.push('/404')
    return;
  }
  // document.title = (to.meta.title ? ` • ${to.meta.title}` : '')
  document.title = (to.meta.title ? ` ${to.meta.title}` : '')
  // if(to.meta.isLogin === true && !store.state['LOGIN']['uid']){
  //   router.replace({
  //     path:"/login",
  //     query:{
  //       redirect_uri:encodeURIComponent(window.location.href)
  //     }
  //   })
  // }
  // Vue.prototype.$common.viewport(
  //   {
  //       width:window.screen.availWidth * 2 < 900 ? 600 : (window.screen.availWidth * 2 > 1400 ? 1400 : window.screen.availWidth * 2), //默认750,在iPhone6模拟器上开发最好
  //       userScalable:"yes", //默认禁止用户手动缩放
  //       maximunScale:2, //默认当前比例基础上缩放1:1
  //       minimumScale:0.5 //默认当前比例基础上缩放1:1
  //   }
  // )
  next();
});

export default router
